import re;

class Context :
	def __init__(self) :
		self.regexp = []
		self.rule = {}
	def addRegexp(self,regexp):
		self.regexp.append(regexp)
	def addRule(self,name,value) :
		self.rule[name] = value
	def p(self):
		 print (self.regexp, self.rule)
		

class Style :
	def __init__(self) :
		self.contexts = []
		
	def addContexts(self,context):
		self.contexts.append(context)
		
	def p(self):
		for x in self.contexts :
			x.p()
		
def parse(name) :
	f = open(name)
	r = Style()
	context = Context()
	isRuleMode = False;
	for x in f:
		if x.startswith("\t") :
			isRuleMode = True;
			tmp = x.split(':')
			context.addRule(tmp[0].strip(),tmp[1].strip())
		else :
			if isRuleMode :
				r.addContexts(context)
				context = Context()
				isRuleMode = False
			#~ context.addRegexp(re.compile(x))
			context.addRegexp(x)

			
	r.addContexts(context)
	return r;


parse("input/base.ks").p()
parse("input/ext.ks").p()

